/*
 * Created on Dec 9, 2004
 */
package persistence.connection;

/**
 * @author Valter Camargo
 *
 */
import java.sql.*;

public abstract class OdbcConnection extends ConnectionManager {
	
	private String currentJdbc;
	private String driver;
	private static String lastJDBC;
	
	
	public OdbcConnection(){
		
		this.currentJdbc = "jdbc:odbc:" + setDSN();
		this.driver = "sun.jdbc.odbc.JdbcOdbcDriver";
		
	}
	
	public abstract String setDSN(); 
	
	public String getCurrentJdbc(){
		return this.currentJdbc;
	}
	
	public String getDriver(){
		return this.driver;
	}
	
	public void setJdbc(String jdbc){
		this.currentJdbc = jdbc;
	}
	
	public void setDriver(String driver){
		this.driver = driver;
	}
	
	public String setJDBC()
	     {
	     	return "jdbc:odbc:" + setDSN();
	     }
	     


    public void ConnectDB () 
    {
     		connect();
    }

	

    public void connect(){
    try
	{
    	Class.forName (driver);
        System.out.println ( "JDBC of this Application: " + currentJdbc);        
        con = DriverManager.getConnection (currentJdbc, userName, password);
        lastJDBC = currentJdbc;
        con.setAutoCommit(true);
        stmt = con.createStatement();   
    }
    catch(ClassNotFoundException e){
    	System.out.println("CATCH: OdbcConnection 1: " + e.getMessage());
    }
    catch(SQLException e){
    	System.out.println("CATCH: OdbcConnection 2: " + e.getMessage());
    }
    }
    

    public void DisconnectDB ()
   {
    try
    {
      System.out.println("The connection will be closed for dsn: " + this.currentJdbc);	
      stmt.close ();
      con.close ();
    }
    catch (Exception e)
    {
     System.out.println ( " *** PROBLEMS TO CLOSE DATABASE ***" );
    }
   }
    
   
	
}
